package it.polimi.traveldream.entity;

import it.polimi.traveldream.dto.ActivityDTO;

import java.io.Serializable;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;

/**
 * The persistent class for the activity database table.
 * 
 */
@Entity
@Table(name = "activity")
@DiscriminatorValue("activity")
@NamedQueries({
		@NamedQuery(name = Activity.FIND_ALL, query = "SELECT a FROM Activity a WHERE a.valid = true"),
		@NamedQuery(name = Activity.FIND_FOR_CITY, query = "SELECT a FROM Activity a WHERE a.city = :city AND a.valid = true") })
public class Activity extends Product implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String FIND_ALL = "Activity.findAll";

	public static final String FIND_FOR_CITY = "Activity.findForCity";

	public enum Type {
		EXCURSION;
	}

	@NotEmpty
	private String city;

	@NotNull
	@Enumerated(EnumType.STRING)
	private Type type;

	public Activity() {
	}

	public Activity(ActivityDTO activity) {
		super(activity);
		this.setCity(activity.getCity());
		this.setType(activity.getType());
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Type getType() {
		return this.type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public void setType(String type) {
		this.setType(Type.valueOf(type));
	}

	@Override
	public ActivityDTO convertToDTO() {
		ActivityDTO activity = new ActivityDTO();
		activity.setCity(this.getCity());
		activity.setDescription(this.getDescription());
		activity.setId(this.getId());
		activity.setName(this.getName());
		activity.setPrice(this.getPrice());
		activity.setType(this.getType().toString());
		activity.setValid(this.getValid());
		return activity;
	}

}